//
//  THDoTaskVC.m
//  YJB
//
//  Created by YJB on 2016/11/28.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THDoTaskVC.h"
#import "THCpcHallModel.h"
#import "Masonry.h"
#import "NJKWebViewProgress.h"
#import "NJKWebViewProgressView.h"

@interface THDoTaskVC ()<UIWebViewDelegate,NJKWebViewProgressDelegate>
@property(nonatomic,strong)UIWebView  *webView;
/** 进度条代理者 */
@property(nonatomic,strong)NJKWebViewProgress *progressProxy;
/** 进度条 */
@property(nonatomic,strong)NJKWebViewProgressView *progressView;

@end

@implementation THDoTaskVC
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"CPC赚钱";
    NSString *urlString = _model.iconUrl;
    if (![urlString hasPrefix:@"http"])
        urlString = [@"http://" stringByAppendingString:urlString];
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:req];
}

- (UIWebView *)webView
{
    if (_webView == nil)
    {
        _webView = [[UIWebView alloc]init];
        _progressProxy = [[NJKWebViewProgress alloc] init];
        _webView.delegate = _progressProxy;
        _progressProxy.webViewProxyDelegate = self;
        _progressProxy.progressDelegate = self;
        [self.view addSubview:_webView];
        _webView.backgroundColor = WHITECOLOR;
        [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_equalTo(0);
        }];
    }
    return _webView;
}

- (NJKWebViewProgressView *)progressView
{
    if (_progressView == nil)
    {
        _progressView = [[NJKWebViewProgressView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_W, 3)];
        _progressView.progressBarView.backgroundColor = APPCOLOR;
        [self.view addSubview:_progressView];
        [self.view bringSubviewToFront:_progressView];
        
    }
    return _progressView;
}

#pragma ------------------------ 进度条代理
- (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [self.progressView setProgress:progress animated:YES];
}


@end
